import Vue from "vue";
import selectTreeComponent from "./selectTree";
import windowComponent from "./window";
import paginationComponent from "./pagination";
import treeComponent from "./tree";
import asidetoggleComponent from "./asidetoggle";
import elLayoutComponent from "./elLayout";
import elLayoutLeftComponent from "./elLayout/components/left.vue";
import elLayoutMainComponent from "./elLayout/components/main.vue";
import selectComponent from "./select";
import dialogComponent from "./dialog";
import formComponent from "./form";
//下拉树
export const selectTree = {
  install: function(Vue) {
    Vue.component("meiSelectTree", selectTreeComponent);
  }
};
//翻页
export const pagination = {
  install: function(Vue) {
    Vue.component("meiPagination", paginationComponent);
  }
};
//树
export const tree = {
  install: function(Vue) {
    Vue.component("meiTree", treeComponent);
  }
};
//右侧收起
export const asidetoggle = {
  install: function(Vue) {
    Vue.component("meiAsideToggle", asidetoggleComponent);
  }
};
//左右布局
export const elLayout = {
  install: function(Vue) {
    Vue.component("meiLayout", elLayoutComponent);
  }
};
//左右布局
export const elLayoutLeft = {
  install: function(Vue) {
    Vue.component("meiLayoutLeft", elLayoutLeftComponent);
  }
};
//左右布局
export const elLayoutMain = {
  install: function(Vue) {
    Vue.component("meiLayoutMain", elLayoutMainComponent);
  }
};
//下拉
export const select = {
  install: function(Vue) {
    Vue.component("meiSelect", selectComponent);
  }
};
//窗口
export const meidialog = {
  install: function(Vue) {
    Vue.component("meiDialog", dialogComponent);
  }
};
//动态表单布局
export const meiform = {
  install: function(Vue) {
    Vue.component("meiForm", formComponent);
  }
};
/**
 * @description 打开一个window
 * @param {Object} com 组件
 * @param {String} title 标题
 * @param {Object} data 参数
 */
export const window = function(com, title, data = {}) {
  if (!com) {
    return;
  }
  const component = Vue.extend(windowComponent);
  let option = Object.assign(
    { component: com },
    { title },
    { options: { ...data } }
  );
  // console.log(option);
  let instance = new component({
    el: document.createElement("div"),
    data: option
  });
  //之前的删掉
  const paras = this.$el.getElementsByClassName("el-dialog__wrapper dialog");
  for (let i = 0; i < paras.length; i++) {
    //删除元素 元素.parentNode.removeChild(元素);
    if (paras[i] != null) paras[i].parentNode.removeChild(paras[i]);
  }
  //添加现在的
  this.$el.appendChild(instance.$el);
  return instance;
};
